from PIL import ImageGrab


def screenshot_win32(imageFilename=None, region=None):

    im = ImageGrab.grab()
    if region is not None:
        assert len(region) == 4, 'region argument must be a tuple of four ints'
        region = [int(x) for x in region]
        im = im.crop((region[0], region[1], region[2] + region[0], region[3] + region[1]))
    if imageFilename is not None:
        im.save(imageFilename)
    return im


img = screenshot_win32(imageFilename='1.png', region=(100, 100,500,200))
print(img)
